package com.lz.gmall.selector;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

//读取到的string都会装配到ioc容器中
public class GmallImportSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {


        try {
            //读取META-INF/spring.factories文件
            InputStream inputStream = GmallImportSelector.class.getClassLoader().getResourceAsStream("META-INF/spring.factories");
            //将配置文件读取到properties文件中
            Properties properties = new Properties();
            properties.load(inputStream);
            String value = properties.getProperty("org.springframework.boot.autoconfigure.EnableAutoConfiguration");
            //如果是多个key，可以采用map的方法获取所有的key，遍历加入String数组中
            return new String[]{value} ;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
